<html>
<head>
  <title>Evernote Export</title>
  <basefont face="微软雅黑" size="2" />
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <meta name="exporter-version" content="YXBJ Windows/601935 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;"/>
  <style>
    body, td {
      font-family: 微软雅黑;
      font-size: 10pt;
    }
  </style>
</head>
<body>
<a name="614"/>

<div>
<span><div style="font-size: 16px; min-width: 100%; position: relative;"><div style="outline: 0px; box-sizing: inherit; text-size-adjust: 100%; -webkit-font-smoothing: antialiased; tab-size: 4;"><div style="min-width: 1200px; outline: 0px; box-sizing: inherit; background-color: rgb(245, 246, 247); font-size: 14px; -webkit-font-smoothing: antialiased; tab-size: 4; zoom: 1;"><div style="outline: 0px; box-sizing: inherit; margin: 0px; padding: 8px 12px 0px; display: flex; -webkit-box-pack: center; justify-content: center; height: 100%;"><div style="outline: 0px; margin: 0px 0px 0px 8px; padding: 0px; box-sizing: border-box; width: 1318px;"><div style="float: right; box-sizing: inherit; outline: 0px; margin: 0px; padding: 0px; width: 1010px;"><div style="outline: 0px; box-sizing: inherit; margin: 0px; position: relative; background: rgb(255, 255, 255); padding: 0px 24px 16px;"><div style="box-sizing: inherit; outline: 0px; margin: 0px; padding: 16px 0px 0px; position: relative;"><div style="outline: 0px; box-sizing: inherit; margin: 0px; padding: 0px; overflow-wrap: break-word;"><div style="outline: 0px; box-sizing: inherit; margin: 0px; padding: 0px; overflow-wrap: break-word; position: relative; min-height: 70px; word-break: break-word;"><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><div><span style="color: rgb(79, 79, 79); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-size: 22px; font-variant-ligatures: common-ligatures; font-weight: bold;">一、崩溃</span><br/></div></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">崩溃率是衡量一个应用质量高低的基本指标，那么，该怎样客观地衡量崩溃这个指标，以及又该如何看待和崩溃相关的稳定性。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">Android 的两种崩溃：</span></div><div style="outline: 0px; list-style: disc; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 0px 32px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 14px; color: rgba(0, 0, 0, 0.75); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 1.625;">Java 崩溃</span></div><div style="outline: 0px; list-style: disc; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 0px 32px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 14px; color: rgba(0, 0, 0, 0.75); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 1.625;">Native 崩溃</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">简单来说，Java 崩溃就是在 Java 代码中，出现了未捕获异常，导致程序异常退出。那 Native 崩溃一般都是因为在 Native 代码中访问非法地址，也可能是地址对齐出现了问题，或者发生了程序主动 Abort，这些都会产生相应的 Signal 信号，导致程序异常退出。</span></div><h4 style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 16px; font-size: 20px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 20px; color: rgb(79, 79, 79); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 28px; font-weight: bold;">1.1 崩溃的收集</span></h4><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">“崩溃”就是程序出现异常，而一个产品的崩溃率，跟我们如何捕获、处理这些异常有比较大的关系。对于很多中小型公司来说，可以选择一些第三方的服务。目前各种平台也是百花齐放，包括阿里的友盟、腾讯的Bugly、网易云捕、Google 的 Firebase 等等。要懂得借力！</span></div><h4 style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 16px; font-size: 20px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 20px; color: rgb(79, 79, 79); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 28px; font-weight: bold;">1.2 ANR</span></h4><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">崩溃率是不是就能完全等价于应用的稳定性呢？答案是肯定不行。处理了崩溃，我们还会经常遇到 ANR（Application Not Responding，程序没有响应）这个问题。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">出现 ANR 的时候，系统还会弹出对话框打断用户的操作，这是用户非常不能忍受的。</span></div><blockquote style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; border-left: 8px solid rgb(221, 223, 228); background: rgb(238, 240, 244); overflow: auto; padding: 16px; margin: 0px 0px 24px; word-break: break-word;"><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 0px; font-size: 14px;"><div><span style="font-size: 14px; color: rgb(153, 153, 153); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">ANR处理方法：</span></div><div><span style="font-size: 14px; color: rgb(153, 153, 153); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">使用 FileObserver 监听 /data/anr/traces.txt 的变化。非常不幸的是，很多高版本的 ROM，已经没有读取这个文件的权限了。这个时候你可能只能思考其他路径，海外可以使用 Google Play 服务，而国内微信利用Hardcoder框架（HC 框架是一套独立于安卓系统实现的通信框架，它让 App 和厂商 ROM 能够实时“对话”了，目标就是充分调度系统资源来提升 App 的运行速度和画质，切实提高大家的手机使用体验）向厂商获取了更大的权限。也可以将手机 ROOT 掉，然后取得 traces.txt 文件。</span></div></div></blockquote><h4 style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 16px; font-size: 20px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 20px; color: rgb(79, 79, 79); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 28px; font-weight: bold;">1.3 应用退出</span></h4><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">除了常见的崩溃，还有一些会导致应用异常退出的情况，例如：</span></div><div style="outline: 0px; list-style: disc; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 0px 32px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 14px; color: rgba(0, 0, 0, 0.75); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 1.625;">主动自杀。Process.killProcess()、exit() 等</span></div><div style="outline: 0px; list-style: disc; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 0px 32px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 14px; color: rgba(0, 0, 0, 0.75); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 1.625;">崩溃。出现了 Java 或 Native 崩溃</span></div><div style="outline: 0px; list-style: disc; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 0px 32px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 14px; color: rgba(0, 0, 0, 0.75); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 1.625;">系统重启。系统出现异常、断电、用户主动重启等，我们可以通过比较应用开机运行时间是否比之前记录的值更小</span></div><div style="outline: 0px; list-style: disc; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 0px 32px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 14px; color: rgba(0, 0, 0, 0.75); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 1.625;">被系统杀死。被 low memory killer 杀掉、从系统的任务管理器中划掉等</span></div><div style="outline: 0px; list-style: disc; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 0px 32px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 14px; color: rgba(0, 0, 0, 0.75); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 1.625;">ANR</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">我们可以在应用启动的时候设定一个标志，在主动自杀或崩溃后更新标志，这样下次启动时通过检测这个标志就能确认运行期间是否发生过异常退出。对应上面的五种退出场景，我们排除掉主动自杀和崩溃（崩溃会单独的统计）这两种场景，希望可以监控到剩下三种的异常退出，理论上这个异常捕获机制是可以达到 100% 覆盖的。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">通过这个异常退出的检测，可以反映如 ANR、low memory killer、系统强杀、死机、断电等其他无法正常捕获到的问题。当然异常率会存在一些误报，比如用户从系统的任务管理器中划掉应用。对于线上的大数据来说，还是可以帮助我们发现代码中的一些隐藏问题。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">根据应用的前后台状态，我们可以把异常退出分为前台异常退出和后台异常退出。“被系统杀死” 是后台异常退出的主要原因，当然我们会更关注前台的异常退出的情况，这会跟 ANR、OOM 等异常情况有更大的关联。</span></div><h3 style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 16px; font-size: 22px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 22px; color: rgb(79, 79, 79); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 30px; font-weight: bold;">二、崩溃处理</span></h3><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">我们每天工作也会遇到各种各样的疑难问题，“崩溃”就是其中比较常见的一种问题。解决问题跟破案一样需要经验，我们分析的问题越多越熟练，定位问题就会越快越准。当然这里也有很多套路，比如对于 “案发现场” 我们应该留意哪些信息？怎样找到更多的 “证人” 和 “线索” ？ “侦查案件” 的一般流程是什么？对不同类型的 “案件” 分别应该使用什么样的调查方式？</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">要相信 “真相永远只有一个”，崩溃也并不可怕。</span></div><h4 style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 16px; font-size: 20px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 20px; color: rgb(79, 79, 79); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 28px; font-weight: bold;">2.1 崩溃现场</span></h4><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">崩溃现场是我们的“第一案发现场”，它保留着很多有价值的线索。现在可以挖掘到的信息越多，下一步分析的方向就越清晰，而不是去靠盲目猜测。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><div><span style="font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px; font-weight: bold; outline: 0px; overflow-wrap: break-word; box-sizing: border-box;">崩溃信息</span></div><div><span style="font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">从崩溃的基本信息，我们可以对崩溃有初步的判断。进程名、线程名。崩溃的进程是前台进程还是后台进程，崩溃是不是发生在 UI 线程。</span></div></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">崩溃堆栈和类型。崩溃是属于 Java 崩溃、Native 崩溃，还是 ANR，对于不同类型的崩溃关注的点也不太一样。特别需要看崩溃堆栈的栈顶，看具体崩溃在系统的代码，还是 APP 代码里面。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px; font-weight: bold;">关键字：FATAL</span></div><div style="outline: 0px; overflow-wrap: break-word; position: relative; box-sizing: border-box; font-size: 14px; border: none; padding: 8px 16px 6px 56px; margin: 0px 0px 24px; background-color: rgb(40, 44, 52);"><div style="outline: 0px; margin: 0px; overflow-wrap: normal; min-width: 94%; box-sizing: border-box; text-size-adjust: none; overflow-x: auto; white-space: pre; font-size: 14px; border-radius: 2px; background-color: rgb(40, 44, 52); padding: 0px; position: unset;"><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">FATAL EXCEPTION: main</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">Process: com.cchip.csmart, PID: 27456</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(int)' on a null object reference</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">at com.cchip.alicsmart.activity.SplashActivity$1.handleMessage(SplashActivity.java:67)</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">at android.os.Handler.dispatchMessage(Handler.java:102)</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">at android.os.Looper.loop(Looper.java:179)</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">at android.app.ActivityThread.main(ActivityThread.java:5672)</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">at java.lang.reflect.Method.invoke(Native Method)</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)</span></div></div></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px; font-weight: bold;">系统信息</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">系统的信息有时候会带有一些关键的线索，对我们解决问题有非常大的帮助。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">Logcat。这里包括应用、系统的运行日志。由于系统权限问题，获取到的 Logcat 可能只包含与当前 APP 相关的。其中系统的 event logcat 会记录 APP 运行的一些基本情况，记录在文件 /system/etc/event-log-tags 中。</span></div><div style="outline: 0px; overflow-wrap: break-word; position: relative; box-sizing: border-box; font-size: 14px; border: none; padding: 8px 16px 6px 56px; margin: 0px 0px 24px; background-color: rgb(40, 44, 52);"><div style="outline: 0px; margin: 0px; overflow-wrap: normal; min-width: 94%; box-sizing: border-box; text-size-adjust: none; overflow-x: auto; white-space: pre; font-size: 14px; border-radius: 2px; background-color: rgb(40, 44, 52); padding: 0px; position: unset;"><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">//system logcat:</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">10-25 17:13:47.788 21430 21430 D dalvikvm: Trying to load lib ...</span></div><div><br/></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">//event logcat:</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">10-25 17:13:47.788 21430 21430 I am_on_resume_called: 生命周期</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">10-25 17:13:47.788 21430 21430 I am_low_memory: 系统内存不足</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">10-25 17:13:47.788 21430 21430 I am_destroy_activity: 销毁 Activty</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">10-25 17:13:47.888 21430 21430 I am_anr: ANR 以及原因</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">10-25 17:13:47.888 21430 21430 I am_kill: APP 被杀以及原因</span></div></div><div style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; padding: 0px 8px; list-style: none; margin: 0px; border-right: 1px solid rgb(197, 197, 197);"><br/></div></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">机型、系统、厂商、CPU、ABI、Linux 版本等。通过采集多达几十个维度，这对寻找共性问题会很有帮助。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px; font-weight: bold;">内存信息</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">OOM、ANR、虚拟内存耗尽等，很多崩溃都跟内存有直接关系。如果把用户的手机内存分为“2GB 以下”和“2GB 以上”两个区，就会发现“2GB 以下”用户的崩溃率是“2GB 以上”用户的几倍。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">系统剩余内存。关于系统内存状态，可以直接读取文件 /proc/meminfo。当系统可用内存很小（低于 MemTotal 的 10%）时，OOM、大量 GC、系统频繁自杀拉起等问题都非常容易出现。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">应用使用内存。包括 Java 内存、RSS（Resident Set Size）、PSS（Proportional Set Size），我们可以得出应用本身内存的占用大小和分布。PSS 和 RSS 通过 /proc/self/smap 计算，可以进一步得到例如 apk、dex、so 等更加详细的分类统计。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">虚拟内存。虚拟内存可以通过 /proc/self/status 得到，通过 /proc/self/maps 文件可以得到具体的分布情况。有时候我们一般不太重视虚拟内存，但是很多类似 OOM、tgkill 等问题都是虚拟内存不足导致的。</span></div><div style="outline: 0px; overflow-wrap: break-word; position: relative; box-sizing: border-box; font-size: 14px; border: none; padding: 8px 16px 6px 56px; margin: 0px 0px 24px; background-color: rgb(40, 44, 52);"><div style="outline: 0px; margin: 0px; overflow-wrap: normal; min-width: 94%; box-sizing: border-box; text-size-adjust: none; overflow-x: auto; white-space: pre; font-size: 14px; border-radius: 2px; background-color: rgb(40, 44, 52); padding: 0px; position: unset;"><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">Name: com.xmamiga.name // 进程名</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">FDSize: 800 // 当前进程申请的文件句柄个数</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">VmPeak: 3004628 kB // 当前进程的虚拟内存峰值大小</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">VmSize: 2997032 kB // 当前进程的虚拟内存大小</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">Threads: 600 // 当前进程包含的线程个数</span></div></div></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">一般来说，对于 32 位进程，如果是 32 位的 CPU，虚拟内存达到 3GB 就可能会引起内存申请失败的问题。如果是 64 位的 CPU，虚拟内存一般在 3～4GB 之间。当然如果我们支持 64 位进程，虚拟内存就不会成为问题。Google Play 要求 2019 年 8 月一定要支持 64 位，在国内虽然支持 64 位的设备已经在 90% 以上了，但是商店都不支持区分 CPU 架构类型发布，普及起来需要更长的时间。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px; font-weight: bold;">资源信息</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">有的时候会发现应用堆内存和设备内存都非常充足，还是会出现内存分配失败的情况，这跟资源泄漏可能有比较大的关系。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">文件句柄 fd。文件句柄的限制可以通过 /proc/self/limits 获得，一般单个进程允许打开的最大文件句柄个数为 1024。但是如果文件句柄超过 800 个就比较危险，需要将所有的 fd 以及对应的文件名输出到日志中，进一步排查是否出现了有文件或者线程的泄漏。</span></div><div style="outline: 0px; overflow-wrap: break-word; position: relative; box-sizing: border-box; font-size: 14px; border: none; padding: 8px 16px 6px 56px; margin: 0px 0px 24px; background-color: rgb(40, 44, 52);"><div style="outline: 0px; margin: 0px; overflow-wrap: normal; min-width: 94%; box-sizing: border-box; text-size-adjust: none; overflow-x: auto; white-space: pre; font-size: 14px; border-radius: 2px; background-color: rgb(40, 44, 52); padding: 0px; position: unset;"><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">opened files count 812:</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">0 -&gt; /dev/null</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">1 -&gt; /dev/log/main4</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">2 -&gt; /dev/binder</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">3 -&gt; /data/data/com.xmamiga.sample/files/test.conf</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">...</span></div></div></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">线程数。当前线程数大小可以通过上面的 status 文件得到，一个线程可能就占 2MB 的虚拟内存，过多的线程会对虚拟内存和文件句柄带来压力。根据我的经验来说，如果线程数超过 400 个就比较危险。需要将所有的线程 id 以及对应的线程名输出到日志中，进一步排查是否出现了线程相关的问题。</span></div><div style="outline: 0px; overflow-wrap: break-word; position: relative; box-sizing: border-box; font-size: 14px; border: none; padding: 8px 16px 6px 56px; margin: 0px 0px 24px; background-color: rgb(40, 44, 52);"><div style="outline: 0px; margin: 0px; overflow-wrap: normal; min-width: 94%; box-sizing: border-box; text-size-adjust: none; overflow-x: auto; white-space: pre; font-size: 14px; border-radius: 2px; background-color: rgb(40, 44, 52); padding: 0px; position: unset;"><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">threads count 412:</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">1820 com.xmamiga.crashsdk</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">1844 ReferenceQueueD</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">1869 FinalizerDaemon</span></div><div><span style="font-size: 14px; color: rgb(171, 178, 191); font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 22px;">...</span></div></div></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">JNI。使用 JNI 时，如果不注意很容易出现引用失效、引用爆表等一些崩溃。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px; font-weight: bold;">应用信息</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">除了系统，其实我们的应用更懂自己，可以留下很多相关的信息。崩溃场景。崩溃发生在哪个 Activity 或 Fragment，发生在哪个业务中; 关键操作路径，不同于开发过程详细的打点日志，我们可以记录关键的用户操作路径，这对我们复现崩溃会有比较大的帮助。其他自定义信息。不同的应用关心的重点可能不太一样。</span></div><h4 style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 16px; font-size: 20px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 20px; color: rgb(79, 79, 79); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 28px; font-weight: bold;">2.2 崩溃分析</span></h4><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">有了这么多现场信息之后，就可以开始真正的“破案”之旅了。绝大部分的 “案件” 只要肯花功夫，最后都能真相大白。不要畏惧问题，经过耐心和细心地分析，总能敏锐地发现一些异常或关键点，并且还要敢于怀疑和验证。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px; font-weight: bold;">第一步：确定重点</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">确认和分析重点，关键在于终过日志中找到重要的信息，对问题有一个大致判断。一般来说，我建议在确定重点这一步可以关注以下几点。</span></div><div style="outline: 0px; list-style: disc; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 0px 32px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 14px; color: rgba(0, 0, 0, 0.75); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 1.625;">确认严重程度。解决崩溃也要看性价比，我们优先解决 Top 崩溃或者对业务有重大影响，例如主要功能的崩溃。不要花几天去解决了一个边角的崩溃，有可能下个版本就把功能删除了。</span></div><div style="outline: 0px; list-style: disc; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 0px 32px;"><div><span style="font-size: 14px; color: rgba(0, 0, 0, 0.75); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 1.625;">崩溃基本信息。确定崩溃的类型以及异常描述，对崩溃有大致的判断。</span></div><div><span style="font-size: 14px; color: rgba(0, 0, 0, 0.75); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 1.625;">一般来说，大部分的简单崩溃经过这一步已经可以得到结论。</span></div></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">Java 崩溃。Java 崩溃类型比较明显，比如 NullPointerException 是空指针，OutOfMemoryError 是资源不足，这个时候需要去进一步查看日志中的 “内存信息”和“资源信息”。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">Native 崩溃。需要观察 signal、code、fault addr 等内容，以及崩溃时 Java 的堆栈。关于各 signal 含义的介绍，你可以查看崩溃信号介绍。比较常见的是有 SIGSEGV 和 SIGABRT，前者一般是由于空指针、非法指针造成，后者主要因为 ANR 和调用 abort() 退出所导致。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">ANR。先看看主线程的堆栈，是否是因为锁等待导致。接着看看 ANR 日志中 iowait、CPU、GC、system server 等信息，进一步确定是 I/O 问题，或是 CPU 竞争问题，还是由于大量 GC 导致卡死。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px; font-weight: bold;">第二步：查找共性</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">如果使用了上面的方法还是不能有效定位问题，我们可以尝试查找这类崩溃有没有什么共性。找到了共性，也就可以进一步找到差异，离解决问题也就更进一步。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">机型、系统、ROM、厂商、ABI，这些采集到的系统信息都可以作为维度聚合，共性问题例如是不是只出现在 x86 的手机，是不是只有三星这款机型，是不是只在 Android 8.0 的系统上。应用信息也可以作为维度来聚合，比如正在打开的链接、正在播放的视频、国家、地区等。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">找到了共性，可以对你下一步复现问题有更明确的指引。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px; font-weight: bold;">第三步：尝试复现</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">如果我们已经大概知道了崩溃的原因，为了进一步确认更多信息，就需要尝试复现崩溃。如果我们对崩溃完全没有头绪，也希望通过用户操作路径来尝试重现，然后再去分析崩溃原因。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">“只要能本地复现，我就能解”，相信这是很多开发跟测试说过的话。有这样的底气主要是因为在稳定的复现路径上面，我们可以采用增加日志或使用 Debugger、GDB 等各种各样的手段或工具做进一步分析。</span></div><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">我们可能会遇到了各种各样的奇葩问题。比如某个厂商改了底层实现、新的 Android 系统实现有所更改，都需要去 Google、翻源码，有时候还需要去抠厂商的 ROM 或手动刷 ROM。很多疑难问题需要我们耐得住寂寞，反复猜测、反复发灰度、反复验证。–但这种问题还是要看问题的严重程序，不可捡了芝麻丢了西瓜。</span></div><h3 style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 16px; font-size: 22px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 22px; color: rgb(79, 79, 79); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 30px; font-weight: bold;">2.3 系统崩溃</span></h3><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">系统崩溃常常令我们感到非常无助，它可能是某个 Android 版本的 Bug，也可能是某个厂商修改 ROM 导致。这种情况下的崩溃堆栈可能完全没有我们自己的代码，很难直接定位问题。能做的有：</span></div><div style="outline: 0px; list-style: disc; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 0px 32px;"><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">查找可能的原因。通过上面的共性归类，我们先看看是某个系统版本的问题，还是某个厂商特定 ROM 的问题。虽然崩溃日志可能没有我们自己的代码，但通过操作路径和日志，可以找到一些怀疑的点。</span></div></div><div style="outline: 0px; list-style: disc; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 0px 32px;"><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">尝试规避。查看可疑的代码调用，是否使用了不恰当的 API，是否可以更换其他的实现方式规避。</span></div></div><div style="outline: 0px; list-style: disc; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 0px 32px;"><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><div><span style="font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">Hook 解决。这里分为 Java Hook 和 Native Hook。它可能只出现在 Android 7.0 的系统中，参考 Android 8.0 的做法，直接 catch 住这个异常。</span></div><div><span style="font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">如果做到了上面说的这些，以上大部分的崩溃应该都能解决或者规避，大部分的系统崩溃也是如此。当然总有一些疑难问题需要依赖到用户的真实环境，这些需要具备类似动态跟踪和调试的能力。</span></div></div></div><h3 style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; margin: 8px 0px 16px; font-size: 22px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 22px; color: rgb(79, 79, 79); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 30px; font-weight: bold;">三、总结</span></h3><div style="outline: 0px; padding: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; margin: 0px 0px 16px;"><span style="outline: 0px; overflow-wrap: break-word; box-sizing: border-box; font-size: 16px; color: rgb(77, 77, 77); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-variant-ligatures: common-ligatures; line-height: 26px;">崩溃攻防是一个长期的过程，我们尽可能地提前预防崩溃的发生，将它消灭在萌芽阶段。作为技术人员，我们不应该盲目追求崩溃率这一个数字，应该以用户体验为先，如果强行去掩盖一些问题往往更加适得其反。我们不应该随意使用 try catch 去隐藏真正的问题，要从源头入手，了解崩溃的本质原因，保证后面的运行流程。在解决崩溃的过程，也要做到由点到面，不能只针对这个崩溃去解决，而应该要考虑这一类崩溃怎么解决和预防。</span></div></div></div></div></div></div></div></div></div></div></div><div><br/></div></span>
</div></body></html> 